#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
#define endl '\n'
const LL MOD = 1e9 + 7;
const int N = 4;
int n; 

class mat
{
public:
    LL m[N][N];
    mat()
    {
        memset(m, 0, sizeof m);
    }
    void clear()
    {
        memset(m, 0, sizeof m);
    }
    mat operator* (const mat& B) const
    {
        mat C;
        for(int i = 1; i <= N - 1; i++)
        {
            for(int j = 1; j <= N - 1; j++)
            {
                for(int k = 1; k <= N - 1; k++)
                {
                    C.m[i][j] = (C.m[i][j] + (m[i][k] * B.m[k][j])) % MOD;
                }
            }
        }
        return C;
    }
}A, RET;

void mat_qpow(LL b)
{
    A.m[1][1] = A.m[1][2] = A.m[2][3] = A.m[3][1] = 1;
    RET.m[1][1] = RET.m[1][2] = RET.m[1][3] = 1; 
    while(b)
    {
        if(b & 1) RET = RET * A;
        A = A * A;
        b >>= 1;
    }
}


void solve() 
{
    A.clear(), RET.clear();
    cin >> n;
    if(n == 1 || n == 2 || n == 3) 
    {
        cout << 1 << endl;
        return;
    }
    mat_qpow(n - 3);
    cout << RET.m[1][1] << endl;
    
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T;
	cin >> T;
	while(T--)
	{
        solve();
	}
	return 0;
}